/*
 * PySL:  Use S-Lang from Python (and vice versa)
 * Copyright (C) 2005,2006 Christopher J. Stawarz <chris@pseudogreen.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */


#ifndef _PYSL_H
#define _PYSL_H


/******************************************************************************
 *
 * Python stuff
 *
 *****************************************************************************/


#include <Python.h>

#ifdef _LIBPYSL_C
#include <numpy/arrayobject.h>
#endif

#ifndef Py_RETURN_NONE
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
#endif

#if PY_VERSION_HEX < 0x02050000

#ifndef Py_ARRAYOBJECT_H
typedef int Py_ssize_t;
#endif

typedef inquiry lenfunc;
typedef intargfunc ssizeargfunc;

#define PyExceptionClass_Check(x) PyClass_Check((x))

#else  /* PY_VERSION_HEX < 0x02050000 */

/* Work around bug in import.h */
#undef PyImport_ImportModuleEx
#define PyImport_ImportModuleEx(n, g, l, f) \
	PyImport_ImportModuleLevel(n, g, l, f, -1)


#endif  /* PY_VERSION_HEX < 0x02050000 */


/******************************************************************************
 *
 * S-Lang stuff
 *
 *****************************************************************************/


#include <slang.h>

#if SLANG_VERSION < 20005
#define SLclass_set_length_function(cl, length) 0
#endif


/******************************************************************************
 *
 * LibPySL stuff
 *
 *****************************************************************************/


#define SAFE_TO_CAST(value, fromtype, totype) \
  ((fromtype)(totype)(value) == (value))

extern char* libpysl_strcatn(int n, ...);
extern char* libpysl_ns_qualify_name(char *name, char *ns_name);

extern PyObject *PySL_SLangError;
extern int SLPy_PythonError;
extern PyObject *LibPySL_Py2SL_Error_Map;
extern PyObject *LibPySL_SL2Py_Error_Map;
extern void libpysl_python_to_slang_error(void);
extern void libpysl_slang_to_python_error(void);

extern PyTypeObject PySL_SLangObject_Type;

extern SLtype SLPy_PyObject_Type;
extern SLang_MMT_Type* slpy_allocate_pyobject(PyObject *obj);
extern int slpy_pop_pyobject(PyObject **obj, SLang_MMT_Type **mmt);

extern int libpysl_push_pyobject(PyObject *obj);
extern PyObject* libpysl_pop_pyobject(void);
extern int libpysl_python_is_toplevel(void);
extern void libpysl_deinit(void);
extern int libpysl_init(int in_python);


#endif  /* !_PYSL_H */
